package com.example.product_practices.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.product_practices.domain.SecurityQuestion;
import com.example.product_practices.service.ISecurityQuestionService;
import com.example.product_practices.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xin.altitude.cms.common.entity.AjaxResult;
import xin.altitude.cms.common.entity.PageEntity;

@RestController
@CrossOrigin
@RequestMapping("/product_practices/security/question")
public class SecurityQuestionController {
    @Autowired
    private ISecurityQuestionService securityQuestionService;
    @Autowired
    IUserService userService;
    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity,SecurityQuestion securityQuestion){
        return AjaxResult.success(securityQuestionService.page(pageEntity.toPage(), Wrappers.lambdaQuery(securityQuestion)));
    }
    @GetMapping("/list")
    public AjaxResult list(SecurityQuestion securityQuestion){
        return AjaxResult.success(securityQuestionService.list(Wrappers.lambdaQuery(securityQuestion)));
    }
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SecurityQuestion securityQuestion) {
        return AjaxResult.success(securityQuestionService.save(securityQuestion));
    }
   @GetMapping("/judge")
    public AjaxResult judge(String userId,String answer1,String answer2){
       Boolean b= securityQuestionService.judge(userId,answer1,answer2);
       if (b){
           String password = userService.getById(userId).getPassword();
           return AjaxResult.success(password);
       }else {
           return  AjaxResult.error("回答错误");
       }

    }
}
